<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //定义无参函数
      function show1() {
        console.log("这是我的第一个函数");
      }
      var show2 = function () {
        console.log("这是我的第二个函数");
      };
      //调用函数
      show1();
      show2();

      //有参函数
      function sum1(a, b) {
        var rs = a + b;
        console.log(rs);
      }
      var sum2 = function (a, b) {
        var rs = a + b;
        console.log(rs);
      };
      sum1(1, 2);
      sum2(2, 3);

      //参数个数匹配:实参个数超过形参个数，将实参个数依次传给形参
      function sum3(a, b) {
        var rs = a + b;
        console.log(rs);
      }
      sum3(1, 2, 7);

      //参数个数匹配:形参个数超过实参个数，将实参个数依次传给形参
      //如果形参没有与实参匹配的值那么形参的值默认为undefined
      function sum4(a, b, c, d) {
        var rs = a + b + c + d;
        console.log(rs); //结果为：NaN不是一个数
        console.log(a, b, c, d);
      }
      sum4(1, 2, 7);

      //立即执行函数（IIFE） 无需被调用自动执行
      (function (a, b, c, d) {
        var rs = a + b + c + d;
        console.log(rs);
        console.log(a, b, c, d);
      })(1, 2, 3, 4);
    </script>
  </body>
</html>
